import type { 
  IEntity, 
  AsyncDataResult, PaginationQuery,
  SaveEntityParams,
  DeleteEntityParams,
  UpdateEntityParams,
  PaginateEntityParams
} from '../../types'
import { HttpClient } from '../../HttpClient'

export class EntityAPI<T = any> implements IEntity<T> {
  private httpClient: HttpClient

  constructor(httpClient: HttpClient) {
    this.httpClient = httpClient
  }

  public async save(params: SaveEntityParams<T>): AsyncDataResult {
    return this.httpClient.request<SaveEntityParams<T>>('save_entity', params)
  }

  public async update(params: UpdateEntityParams): AsyncDataResult {
    return this.httpClient.request<UpdateEntityParams>('update_entity', params)
  }

  public async drop(params: DeleteEntityParams): AsyncDataResult<string> {
    return this.httpClient.request<DeleteEntityParams>('delete_entity', params)
  }

  public async page(params: PaginateEntityParams): AsyncDataResult {
    return this.httpClient.request<PaginateEntityParams>('paginate_entity', params)
  }
}
